package com.headwind.mq.rabbitmq;

import com.google.gson.Gson;
import com.headwind.mq.Constance;
import com.headwind.mq.rabbitmq.message.MyMessage;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : Headwind
 * @version : 1.0
 * @date : Created in 2020/8/10
 * @description : 发送消息
 */
@Component
public class SendMessage {
    private final AmqpTemplate amqpTemplate;

    @Autowired
    public SendMessage(AmqpTemplate amqpTemplate) {
        this.amqpTemplate = amqpTemplate;
    }

    public void send() {
        MyMessage message = new MyMessage("新商品上线了！");
        amqpTemplate.convertAndSend(Constance.MESSAGE_QUEUE_X, "通知：" + new Gson().toJson(message));
    }

}
